var prefix = "/userAunt";
let myDataList=[],myjazSysProjectList=[]
layui.use(['form', 'xmSelect', 'upload', 'laydate'], function () {
    var form = layui.form;
    laydate = layui.laydate;
    AjaxGet( '/userAunt/seleProject'  ).then(function (response){
        if(response.code=='0'){
            myjazSysProjectList=response.data
        }
    }).catch(error => {
        layer.msg(error.msg)
    })
    $('#mySelect').attr("disabled",true);
    AjaxGet( '/userAunt/getUserAunt'  ).then(function (response){
        if(response.code=='0'){
            myDataList=response.data
            //设置select
            $('#mySelect').empty();
            $('#mySelect').append($('<option>', {
                value: '',
                text: '请选择姓名'
            }))
            response.data.forEach(item=>{
                $('#mySelect').append($('<option>', {
                    value: item.sysUserid,
                    text: item.name+'-'+item.mobile
                }))
            })
            $('#mySelect').attr("disabled",false);
            form.render('select');
            selectInput($('#mySelect'),10)
        }
    }).catch(error => {
        layer.msg(error.msg)
    })



    form.on('select(demo-select-filter)', function(data){
        var elem = data.elem; // 获得 select 原始 DOM 对象
        var value = data.value; // 获得被选中的值
        var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
        if(data.value!=""){
            let item=myDataList.find((itemdata)=> itemdata.sysUserid==value)
            //姓名显示
            $('#sex').html(`<span>${item.sex== '1'?'男':'女'}</span>`)
            //
            // myjazSysProjectList
            $('#jazSysProject').html(`<span>${item.projectName}</span>`)
        }else {
            $('#sex').html('<span style="color: rgb(117 117 117);">请先选择姓名</span>')
            $('#jazSysProject').html('<span style="color: rgb(117 117 117);">请先选择姓名</span>')
        }
    });
    lay('.startTime').each(function () {
        laydate.render({
            elem: this
            , trigger: 'click'
            // ,range: true
        });
    });

    //提交事件
    form.on('submit(submit)', function (data) {
          console.log(data.field)
            AjaxPost('/userHouse/insertHouse', {sysUserid:data.field.mySelect,movieHouseTime:data.field.checkTime}).then(function (response) {
                parent.layer.msg("操作成功");
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
                parent.load();
            }).catch(error => {
                layer.msg(error.msg)
            })

    });

});

